// run: $exec < input
#include <iostream>
#include <vector>

int const maxn = 100007;
int head[maxn], end_point[2 * maxn], next[2 * maxn];
bool bad[2 * maxn];
int alloc = 2;
int n;

std::vector<int> ans;

void add_edge(int x, int y, bool is_bad)
{
	end_point[alloc] = y; next[alloc] = head[x];
	bad[alloc] = is_bad;  head[x] = alloc++;

	end_point[alloc] = x; next[alloc] = head[y];
	bad[alloc] = is_bad;  head[y] = alloc++;
}

bool has_bad(int u, int parent, bool is_bad) // to parent edge is bad
{
	bool child_has_bad = false;
	for (int p = head[u]; p; p = next[p]) {
		int v = end_point[p];
		bool tag = bad[p];
		if (v == parent) continue;
		if (has_bad(v, u, tag)) child_has_bad = true;
	}
	if (is_bad && !child_has_bad) ans.push_back(u);
	return is_bad || child_has_bad;
}

int main()
{
	std::ios::sync_with_stdio(false);
	std::cin >> n;
	for (int i = 1, x, y, t; i < n; i++) {
		std::cin >> x >> y >> t;
		add_edge(x, y, t == 2);
	}
	has_bad(1, -1, 0);
	int t = ans.size();
	std::cout << t << '\n';
	for (int i = 0; i < t; i++)
		std::cout << ans[i] << ' ';
	std::cout << '\n';
}

